<!DOCTYPE html>
<html>
<head>
    <title>用户管理</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        .container {
            max-width: 600px;
            margin: auto;
            text-align: center;
        }
        .button {
            display: inline-block;
            margin: 10px;
            padding: 10px 20px;
            background-color: #007BFF;
            color: white;
            text-decoration: none;
            border-radius: 5px;
        }
        .button:hover {
            background-color: #0056b3;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>用户管理</h1>
        <h2>注册新用户</h2>
        <form method="post">
            <input type="hidden" name="action" value="register">
            <label for="username">用户:</label>
            <input type="text" id="username" name="username" required>
            <br>
            <label for="password">密码:</label>
            <input type="password" id="password" name="password" required>
            <br>
            <label for="role">角色:</label>
            <select id="role" name="role">
                <option value="user">普通用户</option>
                <option value="admin">管理员</option>
            </select>
            <br>
            <button type="submit" class="button">注册</button>
        </form>
        <h2>删除用户</h2>
        <form method="post">
            <input type="hidden" name="action" value="delete">
            <label for="user_id">用户ID:</label>
            <input type="text" id="user_id" name="user_id" required>
            <br>
            <button type="submit" class="button">删除</button>
        </form>
        <h2>用户列表</h2>
        <table>
            <thead>
                <tr>
                    <th>ID</th>
                    <th>用户名</th>
                    <th>角色</th>
                </tr>
            </thead>
            <tbody>
                {% for user in users %}
                <tr>
                    <td>{{ user.id }}</td>
                    <td>{{ user.username }}</td>
                    <td>{{ user.role }}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        <h2>注册功能控制</h2>
        <form method="post">
            <input type="hidden" name="action" value="toggle_register">
            <button type="submit" class="button">{{ '关闭' if register_enabled else '开启' }}注册功能</button>
        </form>
        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <div class="{{ category }}">{{ message }}</div>
                {% endfor %}
            {% endif %}
        {% endwith %}
    </div>
</body>
</html>